<%  has_string = entity.cases.all? { |c| !c.string.nil? } -%>
<%  type = entity.raw_type ? JavaHelper.type(entity.raw_type) : 'int' -%>
public enum <%= entity.name %> {
<%# Cases -%>
<%  entity.cases.each_with_index do |c, i| -%>
    <%= JavaHelper.format_constant(c.name) %><% unless c.value.nil? %> (<% if type != 'int' %>(<%= type %>) <% end %><%= c.value %><% end %>)<% if i < entity.cases.size - 1 %>,<% else %>;<% end %>
<%  end -%>
<%# Value -%>
<%  if entity.cases.any? { |e| !e.value.nil? } -%>

    private final <%= type %> value;
    <%= entity.name %>(<%= type %> value) {
        this.value = value;
    }
    public <%= type %> value() { return value; }

    public static <%= entity.name %> createFromValue(<%= type %> value) {
        switch (value) {
<%  entity.cases.each_with_index do |c, i| -%>
            case <% if type != 'int' %>(<%= type %>) <% end %><%= c.value %>: return <%= entity.name %>.<%= JavaHelper.format_constant(c.name) %>;
<%  end -%>
            default: return null;
        }
    }

<%  end -%>
<%# Property declarations -%>
<%- entity.properties.each do |property| -%>
<%-   if should_return_data(property) -%>
    public native byte[] <%= JavaHelper.format_name(property.name) %>(<%= JavaHelper.parameters(property.parameters.drop(1)) %>);
<%-   else -%>
    public native <%= JavaHelper.type(property.return_type) %> <%= JavaHelper.format_name(property.name) %>(<%= JavaHelper.parameters(property.parameters.drop(1)) %>);
<%-   end -%>
<%- end -%>
<%# Method declarations -%>
<%- entity.methods.each do |method| -%>
<%-   next if method.name.start_with?('Delete') -%>
<%-   if should_return_data(method) -%>
    public native byte[] <%= JavaHelper.format_name(method.name) %>(<%= JavaHelper.parameters(method.parameters.drop(1)) %>);
<%-   else -%>
    public native <%= JavaHelper.type(method.return_type) %> <%= JavaHelper.format_name(method.name) %>(<%= JavaHelper.parameters(method.parameters.drop(1)) %>);
<%-   end -%>
<%- end -%>
<%# toString -%>
<%  if has_string -%>

    public String toString() {
        switch (this) {
<%    entity.cases.each do |c| -%>
        case <%= JavaHelper.format_constant(c.name) %>: return <%= c.string %>;
<%    end -%>
        default: return "";
        }
    }
<%  end -%>
}
